﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Common;
using AutoFacUtils;
using CashFlow.Db.DAL;
using CashFlow.Db.Entity;
using CashFlow.Db.IRepository;
using SysTool._00_Def;

namespace SysTool._02_Service
{
    public class ShopUserService
    {
        public static IList<UserInfoAndReferenceUserInfo> QueryShopAllUsers(int shopManagerUserId)
        {
            using (var db = SqlSugarHelper.GetDb())
            {
                var ls = db.Queryable<ShopUserEntity>()
                    .InnerJoin<UserInfoEntity>((su, u1) => su.UserId == u1.Id)
                    .InnerJoin<UserInfoEntity>((su, u1, u2) => u1.ReferenceInvitationCode == u2.InvitationCode)
                    .Where((su, u1, u2) => su.ShopManagerUserId == shopManagerUserId)
                    .Select((su, u1, u2) => new UserInfoAndReferenceUserInfo
                    {
                        UserInfo = u1,
                        ReferenceUserInfo = u2
                    })
                    .ToList();
                return ls;
            }
        }

        public static IList<int> QueryShopAllUserIds(int shopManagerUserId)
        {
            using (var db = SqlSugarHelper.GetDb())
            {
                var ls = db.Queryable<ShopUserEntity>()
                    .Where(x => x.ShopManagerUserId == shopManagerUserId)
                    .Select(x => x.UserId)
                    .ToList();
                return ls;
            }
        }
    }
}
